<template>
  <div class="app-container">
    <el-card style="margin-bottom: 10px">
      <h1 style="margin: 0">《{{ courseName }}》选课名单</h1>
    </el-card>
    <el-card>
      <el-table v-loading="loading" :data="studentList">
        <el-table-column label="姓名" align="center" prop="name" />
        <el-table-column label="性别" align="center" prop="sex">
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.sys_user_sex"
              :value="scope.row.sex"
            />
          </template>
        </el-table-column>
        <el-table-column label="学号" align="center" prop="schoolNumber" />
        <el-table-column label="手机号" align="center" prop="phone" />
        <el-table-column label="年龄" align="center" prop="age" />
        <el-table-column label="年级" align="center" prop="grade">
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.ocss_grade"
              :value="scope.row.grade"
            />
          </template>
        </el-table-column>
        <el-table-column label="国籍" align="center" prop="nationality" />
        <el-table-column label="籍贯" align="center" prop="nativePlace" />
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
  </div>
</template>

<script>
import { listCourseDetail } from "@/api/system/course";

export default {
  name: "CourseDetail",
  dicts: ["sys_user_sex", "ocss_grade"],
  data() {
    return {
      // 总条数
      total: 0,
      // 学生信息表格数据
      studentList: [],
      loading: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      courseId: 0,
      courseName: "",
    };
  },
  created() {
    this.courseId = this.$route.params.id;
    this.courseName = this.$route.params.name;
  },
  mounted() {
    this.getList();
  },
  methods: {
    /** 查询学生信息列表 */
    getList() {
      this.loading = true;
      listCourseDetail(this.queryParams, this.courseId).then((response) => {
        this.studentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
  },
};
</script>
